<?php
//
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
$setting=$this->plugin_setting('basic');
$return['setting']=$setting;
//置顶计算：
$this->model('model')->uptoptime();
if($_RQ['op']=='main'){
	$return['groups']=pdo_getall('jy_zhaopin_job_group',array('status'=>1,'uniacid'=>$_SESSION['uniacid']),array('id','title','image'),'','id desc');
	$setting['bankuai1'] =  !empty($setting['bankuai1']) ? $setting['bankuai1'] : $bankuai1;
	$setting['footernav'] = !empty($setting['footernav']) ? $setting['footernav'] : $footernav;
	$return['pcd']=$this->session('pcd')?:array();
	if($return['pcd']){
		$address=$return['pcd']['province'].' '.$return['pcd']['city'];
		$code=pdo_getcolumn('core_area',array('address'=>$address),'parent_code');
	}
	$return['sharedata']=array(
		'title'=>$setting['share_title'],
		'desc'=>$setting['share_desc'],
		'link'=>custom_url('jy_zhaopin/index//code='.$code,true),
		'imgUrl'=>$setting['share_image'],
	);
	$return['params']=array();
	$return['setting']=$setting;
	$return['member']=pdo_get('core_members',array('id'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']),array('createtime','credit1','credit2','mobile','avatar','nickname'));

	set_html('title',$setting['title']?$setting['title'] :'招聘信息');
	$return['notices']=pdo_getall('core_account_article',array('uniacid'=>$_SESSION['uniacid'],'status'=>'1'),'','id desc');
	exi($return);
}	
// js 获取数据
if($_RQ['op']=='getlist'){
	$post=get_postdata();
	$params=array(
		'uniacid'=>$_SESSION['uniacid'],
		'status'=>1,
	);
	if(trim($_RQ['keyword'])){
		$params['title like']='%'.trim($_RQ['keyword']).'%';
		$return['params']['keyword']=trim($_RQ['keyword']);
	}
	if($_RQ['pid']){
		$params['type']=intval($_RQ['pid']);
		$return['params']['pid']=intval($_RQ['pid']);
	}
	if($_RQ['cid']){
		$params['ccate']=intval($_RQ['cid']);
		$return['params']['ccate']=intval($_RQ['cid']);
	}
	if($_RQ['ishot']){
		$params['ishot']=intval($_RQ['ishot']);
	}
	$return['params']['jsjuli']=intval($_RQ['jsjuli']);
	$return['params']['ishot']=intval($_RQ['ishot']);
	if($_RQ['priceMin']){
		$params['price >=']=$_RQ['priceMin'];
		$return['params']['priceMin']=intval($_RQ['priceMin']);
	}
	if($_RQ['priceMax']){
		$params['price <=']=$_RQ['priceMax'];
		$return['params']['priceMax']=intval($_RQ['priceMax']);
	}
	if($post['pcd']){
		if($post['pcd']['city']){
			if($post['pcd']['city']=='北京市' || $post['pcd']['city']=='上海市' || $post['pcd']['city']=='天津市'){
				$address=$post['pcd']['city'].' 市辖区';
			}else{
				$address=$post['pcd']['province'].' '.$post['pcd']['city'];
			}
			$code=pdo_getcolumn('core_area',array('address'=>$address),'parent_code');
			$params['code']=$code;
			$return['params']['code']=$code;
			$this->session('pcd',$post['pcd']);
		}
	}	
	
	//进一步整理筛选条件，商品属性字段是否需 要调整，商品分类如何筛选，orderby如何整理
	$pindex = max(1, intval($_RQ['page']));
	$psize = 20;
	if(intval($_RQ['num'])){
		$psize=$_RQ['num'];
	}
	if($_RQ['isitem']){
		$return['params']['isitem']=1;
		$psize=$setting['item_nums']?:10;
	}
	$total='';
	$fields=array('id','ishot','title','remark','images','mid','type','price','looks','lat_lng','redmoney','createtime','province','city','district','address');
	$orderby='paixu desc,ishot desc,id desc ';
	if($_RQ['order']){
		if($_RQ['order']=='sales'){
			$orderby='looks desc';
		}
		if($_RQ['order']=='price'){
			if($_RQ['order_type']==2){
				$orderby='price desc';
			}else{
				$orderby='price asc';
			}
		}
	}
	$parameter=array(
		'params'=>$params,
		'limit'=>array($pindex,$psize),
		'fields'=>$fields,
		'orderby'=>$orderby,
	);
	if($_RQ['isjuli'] || $_RQ['isitem']){
		$list=pdo_getall('jy_zhaopin_job',$params,$fields,'',$orderby);
	}else{
		$list=pdo_getslice('jy_zhaopin_job',$params,array($pindex,$psize),$total,$fields,'',$orderby);	
	}
	$lat_lng=$this->session('lat_lng');
	if($_RQ['lat'] && $_RQ['lng']){
		$lat_lng=array('lat'=>$_RQ['lat'],'lng'=>$_RQ['lng']);
		$this->session('lat_lng',$lat_lng);
		$return['params']['lat']=$_RQ['lat'];
		$return['params']['lng']=$_RQ['lng'];
	}
	if($list){
		foreach($list as &$item){
			$item['createtime']=date('Y-m-d H:m:s',$item['createtime']);
			$item['lat_lng']=json_decode($item['lat_lng'],true);
			if($lat_lng && $item['lat_lng']['lng'] && $item['lat_lng']['lat']){
					$item['juli']=cfc('tools')->getdistance($lat_lng['lng'],$lat_lng['lat'],$item['lat_lng']['lng'],$item['lat_lng']['lat']);
					$item['juli']=intval($item['juli']/1000);
			}
			$item['member']=pdo_get('core_members',array('id'=>$item['mid']));
			$item['images']=json_decode($item['images'],true);
			$item['isme']=$item['mid']==$_SESSION['uid'] ? 1 :0;
			$item['isshoucang']=pdo_getcolumn('jy_zhaopin_shoucang',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'itemid'=>$item['id']),'isshoucang');
			$item['msg']=pdo_getall('jy_zhaopin_comment',array('status'=>1,'uniacid'=>$_SESSION['uniacid'],'itemid'=>$item['id']),'','createtime desc');
			if($item['msg']){
				foreach($item['msg'] as &$m){
					$m['createtime'] = date('Y-m-d H:i',$m['createtime']);
					$m['member'] = pdo_get('core_members',array('id'=>$m['mid'],'uniacid'=>$_SESSION['uniacid']),array('credit1','credit2','mobile','avatar','nickname'));
				}
			}
			$item['merchid']=pdo_getcolumn('jy_merch_user',array('mid'=>$item['mid'],'uniacid'=>$_SESSION['uniacid']),'id');
		}
	}
	if($_RQ['isjuli']){
		paixu($list,'juli','asc');
	}
	$return['list']=$list;
	exi($return);
}
if($_RQ['op']=='getpcd'){
	if(!empty($_RQ['keyword'])){
			$params['title like']='%'.$_RQ['keyword'].'%';
			$return['params']['title']=$_RQ['keyword'];
	}
	$areas=cfc('area')->get_pcd_titlelist($_RQ['keyword']);
	$return['areas']=$areas;
	exi($return);
}
if($_RQ['op']=='shoucang'){
	$postdata=get_postdata();
	$id = intval($postdata['pid']);
	if(!$id){
		exi('没有找到该信息，请重新选择！','error');
	}
	$shoucang=pdo_get('jy_zhaopin_shoucang',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'itemid'=>$id));
	if($shoucang){
		if($shoucang['isshoucang'] !=1){
			pdo_update('jy_zhaopin_shoucang',array('isshoucang'=>1,'createtime'=>TIMESTAMP),array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'itemid'=>$id));
			exi('收藏成功');
		}else{
			pdo_update('jy_zhaopin_shoucang',array('isshoucang'=>0),array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'itemid'=>$id));
		   exi('取消收藏');
		}
	}else{
		$insert=array(
			'uniacid'=>$_SESSION['uniacid'],
			'itemid'=>$id,
			'mid'=>$_SESSION['uid'],
			'isshoucang'=>1,
			'createtime'=>TIMESTAMP
		);
		pdo_insert('jy_zhaopin_shoucang',$insert);
	}
	exi('收藏成功');
}
if($_RQ['op']=='setmsg'){
	$postdata=get_postdata();
	$item=pdo_get('jy_zhaopin_job',array('uniacid'=>$_SESSION['uniacid'],'id'=>intval($postdata['pid'])));
	$data=array(
		'comment'=>trim($postdata['msg']),
		'mid'=>$_SESSION['uid'],
		'itemid'=>intval($postdata['pid']),
		//'cid'=>intval($postdata['cid']),
		'uniacid'=>$_SESSION['uniacid'],
		'item_mid'=>$item['mid'],
		'typeid'=>$item['type'],
		'status'=>1,
		'createtime'=>time(),
	);
	$msg='评论成功！';
	if($setting['msg_shenhe']){
		$data['status']=0;
		$msg='评论成功,等待审核！';
	}
	pdo_insert('jy_zhaopin_comment',$data);
	exi($msg);
}
if($_RQ['op']=='del'){	
	if(!$_RQ['id']){
		exi('信息不存在哦！','error');
	}	
	pdo_delete('jy_zhaopin_job',array('uniacid'=>$_SESSION['uniacid'],'id'=>$_RQ['id']));
	exi('删除成功！');

}
?>